using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for VariablesAdaptor.
	/// </summary>
	public class VariablesAdaptor : Adaptor, IRefreshable
	{
    private ColumnCollection variables;
    public VariablesAdaptor(ColumnCollection variables)
		{
			this.variables = variables;
		}

    public override void AddChildren(System.Windows.Forms.TreeNode node)
    {
      foreach (Column variable in variables)
      {
        // versions
        TreeNode varNode = TreeNodeFactory.CreateTreeNode(new VariableAdaptor(variable));
        node.Nodes.Add(varNode);
      }
    }

    public override string Text
    {
      get
      {
        return "Variables (" + variables.Count + ")";
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 26;
      }
    }

    public override Control GetRenderer()
    {
      VariablesControl control = new VariablesControl();
      control.LoadVariables(variables);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control; 
    }

    public override object Object
    {
      get
      {
        return variables;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      variables.Refresh();
    }

    #endregion
  }
}
